package com.im.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.im.app.mapper.GroupMemberMapper;
import com.im.app.service.IGroupMemberService;
import com.im.app.utils.text.Convert;
import org.jim.core.packets.GroupMember;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class IGroupMemberServiceImpl extends ServiceImpl<GroupMemberMapper, GroupMember> implements IGroupMemberService {

    @Resource
    private GroupMemberMapper groupMemberMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param groupId 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public List<GroupMember> selectGroupMemberByGroupId(String groupId)
    {
        return groupMemberMapper.selectGroupMemberByGroupId(groupId);
    }

    @Override
    public GroupMember selectGroupMember(String groupId,String memberId){
        QueryWrapper<GroupMember> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("group_id",groupId);
        queryWrapper.eq("user_id",memberId);
        List<GroupMember> groupMembers = groupMemberMapper.selectList(queryWrapper);
        if (groupMembers.size() > 0){
            return groupMembers.get(0);
        }
        return null;
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param groupMember 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<GroupMember> selectGroupMemberList(GroupMember groupMember)
    {
        return groupMemberMapper.selectGroupMemberList(groupMember);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param groupMember 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertGroupMember(GroupMember groupMember)
    {
        return groupMemberMapper.insertGroupMember(groupMember);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param groupMember 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateGroupMember(GroupMember groupMember)
    {
        return groupMemberMapper.updateGroupMember(groupMember);
    }


    /**
     * 批量删除【请填写功能名称】
     *
     * @param userId 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteGroupMemberByUserId(String userId)
    {
        return groupMemberMapper.deleteGroupMemberByUserId(userId);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param groupId 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteGroupMemberByGroupId(String groupId)
    {
        return groupMemberMapper.deleteGroupMemberByGroupId(groupId);
    }

}
